import math
from libavg import avg
from panels.wind import WindPanel
import random

# this trash object is destroyable by a pinch apart move
class Trash(avg.ImageNode):
    

    def __init__(self, x, par, weight, img):
        self.animDown = None# stores current downward falling animation
        self.animSide = None# stores current sideways falling animation
        self.anim = None# stores the current parallel animation
        self.weight = weight        
        self.wind = 0
        self.__updateable = True
        self.parent=par
        self.img=avg.ImageNode.__init__(self, href="../data/img/"+img, parent = par,angle = random.uniform(0,3.14),pos=(x,-100))
     
	# method call for indicating if object is locked by user or updateable
    def updateable(self):
        return self.__updateable

    # handler to initiate falling of object
    def fallDown(self, wind):
        self.wind = wind
        # stop previous animations
        if self.anim is not None:
            self.anim.abort() # abort previous animation
        self.anim = avg.ContinuousAnim(self,'pos',self.pos,(wind*3,(11-self.weight)*30)) # calculate new animation parameters
        self.anim.start()
		
    # trash fade out procedure
    def fadeOut(self):
        if self.anim is not None:
            self.anim.abort() # abort previous animation            
        trashList = self.parent.getTrashList() #deletes itself from the simulator trashlist
        if self in trashList:
            trashList.remove(self)            
        avg.fadeOut(self, 300).start() # the actual fade out animation
    
    #function for calculating distance between two 2DPoint Objects, requires import math
    def getDistance(self, p, q): 
        return math.sqrt((p.x-q.x)**2 + (p.y-q.y)**2)
    
    def getWeight(self):
        return self.weight
        